package sort;

/**
 * 冒泡排序
 */
public class BubbleSort {

    public static void main(String[] args) {

        int[] nums = new int[]{1,5,8,2,3,9,4};
        System.out.println("从小到大排序后的结果是:");
        int[] numbers = bubble(nums);
        for(int i=0;i<numbers.length;i++){
            System.out.print(numbers[i]+" ");
        }
    }

    public static int[] bubble(int[] nums){
        for(int i=0;i<nums.length-1;i++) {
            for(int j=0;j<nums.length-1-i;j++) {
                if(nums[j]>nums[j+1]) {
                    int temp=nums[j];
                    nums[j]=nums[j+1];
                    nums[j+1]=temp;
                }
            }
        }
        return nums;
    }
}
